Create a HTTP server, that listens to a specific port and processes requests through the specified callback.
hostname | string | The hostname to which the server is listening Default value: 'localhost' |
port | integer|NaN | The port to which the server is listening NaN if no server is active. |
running | boolean | Status of the server |
Create a HTTP server, that listens to a specific port and processes requests through the specified callback.
obj = Server(hostname, port, callback, keystore, keystorepassword, keymanagerpassword)
hostname | string | name of the host on which the server runs, e.g. localhost or the Docker container name. |
port | integer | port on which the server is listening. |
callback | function | (optional) if not specified the server does not process any requests. The signature of callback is callback(event), where "event" is an object of type modelit.web.server.HttpExchange. The function callback produces no output argument, but must use the method event.send when done. |
keystore | string | (optional) filename of the .jks file. |
keystorepassword | string | (optional) Password for the keystore. |
keymanagerpassword | string | (optional) Password for the keymanager. |
obj | modelit.web.server.Server | Documentation for modelit.web.server.Server/Server doc modelit.web.server.Server |
Stop the server.
obj = stop(obj)
obj | modelit.web.server.Server |
obj | modelit.web.server.Server | The server is stopped. |
Start the server to listen on the selected port.
obj = start(obj)
obj | modelit.web.server.Server |
obj | modelit.web.server.Server | the servers is started and listens to the selected port. |
Remove a callback for the specified path.
removeContext(obj, path)
obj | modelit.web.server.Server | |
path | string | The path from which the callback has to be removed. Note that adding a different context removes the old context, so no explicit removal of the context is needed. |
No direct output, the callback for the specified path has been removed.
Add a callback for request on the specified port. Username and password can be specified to require authentication on this specific path.
addContext(obj, path, callback, username, password)
obj | modelit.web.server.Server | |
path | string | valid URL path, e.g. /resource/value |
callback | any | <(modelit.web.server.HttpExchange) => void> the HttpExchange object contains all information of the request and all methods to return a response to the sender. |
username | string | optional username when authentication is needed. |
password | string | optional password when authentication is needed. |
No output.
Callback executed when the server receives a request. It triggers a second callback in which the callback provided by the user is called with a modelit.web.server.HttpExchange object containing all the necessary information of the request and all the methods to send a response back the sender.
processRequest(obj, event, currentContextCallback)
obj | any | |
event | nl.modelit.web.server.ServerEvent | Java object. |
currentContextCallback | functionhandle | The callback specified by the user for the current context, executed with a modelit.web.server.HttpExchange object containing all the necessary information of the request and all the methods to send a response back the sender. |
No output.